package com.sghj.Interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * @author xrx
 * @Date 2022/2/14
 * @apiNote
 */
@Configuration
public class MyInterceptors implements WebMvcConfigurer {
    // 不需要静态资源：这里面包含HTML、CSS、JS、图片等等，不需要查数据库也不需要程序处理，直接就能够显示的页面。
     private static final List<String> EXCLUDE_PATH = Arrays.asList("/", "css/**", "js/**", "img/**", "json/**", "fonts/**","/*.html");
    //不需认证的接口
     private static final List<String> UNAUTHENTICATION_PATH = Arrays.asList("/schedule/getNorthHallList","/schedule/getSouthHallList","/schedule/getTakeawayList","/schedule/getOtherList");

     @Override
     //添加访问路径
    public void addResourceHandlers(ResourceHandlerRegistry registry){
         registry.addResourceHandler("/static/**");
     }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(authenticationInterceptor())//配置，验证
                .addPathPatterns("/**") //要拦截的请求
                .excludePathPatterns(EXCLUDE_PATH)
                //不拦截的请求
                .excludePathPatterns("/sysUser/login")              //后台登录
                .excludePathPatterns("/user/frontLogin")            //前台登录
                .excludePathPatterns("/pageviews/getpageviews")     //访问量
                .excludePathPatterns("/sysUser/ceshi")              //测试接口
                //.excludePathPatterns("/error")
//                .excludePathPatterns("/washtype/**")               //洗衣接口
                .excludePathPatterns("/washcommodity/**")
                .excludePathPatterns("/picture/**")
                .excludePathPatterns("/employee/addAudit")
                .excludePathPatterns("/appointment/getNorthHallList","/appointment/getTakeawayList","/appointment/getSouthHallList","/appointment/getOtherList");         //小程序的获取外卖列表接口
                //.excludePathPatterns("/locker/**")                  //货柜接口
//                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**", "/doc.html/**");
    }

    @Bean
    public AuthenticationInterceptor authenticationInterceptor(){
        return new AuthenticationInterceptor();
    }
}
